﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ClassLibrary.Data;
using ClassLibrary.Entity;
using System.Data;

namespace ClassLibrary.DAO
{
    public class TblPhonesDAO
    {
        DBService _db = null;
        public TblPhonesDAO(string ConnectionString)
        {
            _db = new DBService(ConnectionString);
        }
        public DataTable InsUpdPhone(TblPhones phone, int mode)
        {
            DataTable dt = null;
            try
            {
                dt = _db.ExeSP_DataTable("sp_TblPhones_InsUpd",
                    new string[] {"@PhoneID","@IMEINo", "@Model", "@Manufacturer", "@PhoneBrand", "@PhoneMSN", 
								  "@PhoneCondition", "@PhoneConditionDetails", "@PhoneNetworkWith", "@LockPhone", "@mode" },
                    new object[] {phone.PhoneID, phone.IMEINo, phone.Model, phone.Manufacturer, phone.PhoneBrand, phone.PhoneMSN,
                                  phone.PhoneCondition, phone.PhoneConditionDetails, phone.PhoneNetworkWith, phone.LockPhone, mode},
                    CommandType.StoredProcedure);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return dt;
        }

        public DataTable GetPhoneById(int PhoneId)
        {
            DataTable dt = null;
            try {
                dt = _db.ExeSP_DataTable("select * from TblPhones where PhoneID = @PhoneId",
                    new string[] { "@PhoneId" },
                    new object[] { PhoneId},
                    CommandType.Text);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return dt;
        }

        public DataTable GetPhoneID(int JobID)
        {
            DataTable dt = null;
            try
            {
                dt = _db.ExeSP_DataTable("select JobId, Model, PhoneBrand from TblPhones, TblJobs " +
                                "where TblPhones.PhoneID = TblJobs.PhoneID and JobID=@JobID",
                new string[] { "@JobID" },
                new object[] { JobID }, CommandType.Text);

            }
            catch (Exception ex)
            {
                throw ex;
            }
            return dt;
        }
      
    }
}
